package system;

import javax.servlet.http.HttpServletRequest;
import models.Role;

/**
 * class UserIdentity
 * 
 * @author Rezan Achmad
 */
public class UserIdentity {

    public HttpServletRequest request;

    public UserIdentity(HttpServletRequest request) {
        this.request = request;
    }

    public UserIdentity getInstance(HttpServletRequest request) {
        return new UserIdentity(request);
    }

    public boolean isGuest() {
        return getRoleId() == 0;
    }

    public boolean isUser() {
        return getRoleId() == Role.USER;
    }

    public boolean isAdmin() {
        return getRoleId() == Role.ADMIN;
    }
    
    public boolean isManager() {
        return getRoleId() == Role.MANAGER;
    }

    public int getRoleId() {
        try {
            return (Integer) Session.get(request, "role_id");
        } catch (Exception e) {
        }

        return 0;
    }

    public int getUserId() {
        try {
            return (Integer) Session.get(request, "user_id");
        } catch (Exception e) {
        }

        return 0;
    }

    public String getEmail() {
        try {
            return (String) Session.get(request, "email");
        } catch (Exception e) {
        }

        return "";
    }

    public String getNamaPanggilan() {
        try {
            return (String) Session.get(request, "nama_panggilan");
        } catch (Exception e) {
        }

        return "";
    }
}
